class Node:
    def __init__(self, num=None, key=None):
        self.num = num
        self.key = key
        self.next = None


class LinkList:  # 自定义节点
    def __init__(self):
        self.head = Node()

    def create(self, a):
        tail = self.head
        for i in range(len(a)):
            p = Node(i + 1, a[i])
            tail.next = p
            tail = p
        tail.next = self.head


def solve(la, n):
    q = p = la.head
    res = []
    cnt = 0
    m = 6
    while n > 0:
        cnt += 1
        p = p.next
        if p == la.head:
            q = p
            p = p.next
        if cnt == m:
            res.append(p.num)
            m = p.key
            q.next = p.next
            n -= 1
            cnt = 0
        else:
            q = p
    print(*res)

for i in range(2):
    la = LinkList()
    la.create([3,1,7,2,4,8,4])
solve(la,7)